cmake_minimum_required(VERSION 3.22)
project(src)

#指定可执行文件输出位置
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build)

#指定头文件目录
list(APPEND EXTAR_INCLUDE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/binder
                                 ${CMAKE_CURRENT_SOURCE_DIR}/common
                                 ${CMAKE_CURRENT_SOURCE_DIR}/common/config
                                 ${CMAKE_CURRENT_SOURCE_DIR}/common/context
                                 ${CMAKE_CURRENT_SOURCE_DIR}/common/type
                                 ${CMAKE_CURRENT_SOURCE_DIR}/expression
                                 ${CMAKE_CURRENT_SOURCE_DIR}/function
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator/agg
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator/filter
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator/helper
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator/join
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator/join/hashjoin
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator/join/nestedloopjoin
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator/join/radixjoin
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator/order
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator/project
                                 ${CMAKE_CURRENT_SOURCE_DIR}/operator/scan
                                 ${CMAKE_CURRENT_SOURCE_DIR}/pipeline
                                 ${CMAKE_CURRENT_SOURCE_DIR}/pipeline/execute
                                 ${CMAKE_CURRENT_SOURCE_DIR}/planner
                                 ${CMAKE_CURRENT_SOURCE_DIR}/sche
                                 ${CMAKE_CURRENT_SOURCE_DIR}/storage
                                 ${CMAKE_CURRENT_SOURCE_DIR}/util                                                    
                                 ${CMAKE_CURRENT_SOURCE_DIR}/test)


#添加源文件
file(GLOB_RECURSE SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp                       
                            ${CMAKE_CURRENT_SOURCE_DIR}/binder/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp 
                            ${CMAKE_CURRENT_SOURCE_DIR}/common/config/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/common/context/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/common/type/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/expression/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/function/*.cpp 
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/agg/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/filter/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/helper/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/join/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/join/hashjoin/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/join/nestedloopjoin/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/join/radixjoin/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/order/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/project/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/operator/scan/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/pipeline/*.cpp 
                            ${CMAKE_CURRENT_SOURCE_DIR}/pipeline/execute/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/planner/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/sche/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/storage/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/util/*.cpp
                            ${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp )


add_library(${PROJECT_NAME} ${SRC_FILES})


#添加头文件搜索目录
target_include_directories(${PROJECT_NAME} PUBLIC ${EXTAR_INCLUDE_HEADER})

########################################添加依赖库-start########################################
## 添加jemalloc
find_library(JEMALLOC_LIB jemalloc)
if (JEMALLOC_LIB)
    target_link_libraries(${PROJECT_NAME} PRIVATE ${JEMALLOC_LIB})
    message(STATUS "jemalloc library found at: ${JEMALLOC_LIB}")
else ()
    message(FATAL_ERROR "jemalloc not found")
endif ()

########################################添加依赖库-end########################################
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog)
target_link_libraries(${PROJECT_NAME} PRIVATE Arrow::arrow_shared)
target_link_libraries(${PROJECT_NAME} PRIVATE duckdb_pg_query)
target_link_libraries(${PROJECT_NAME} PRIVATE fmt)
